package de.stefanocke.roo.wicket;

import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.springframework.roo.model.JavaPackage;
import org.springframework.roo.shell.CliAvailabilityIndicator;
import org.springframework.roo.shell.CliCommand;
import org.springframework.roo.shell.CliOption;
import org.springframework.roo.shell.CommandMarker;

/**
 * Sample of a command class. The command class is registered by the Roo shell
 * following an automatic classpath scan. You can provide simple user
 * presentation-related logic in this class. You can return any objects from
 * each method, or use the logger directly if you'd like to emit messages of
 * different severity (and therefore different colours on non-Windows systems).
 * 
 * @since 1.1
 */
@Component
// Use these Apache Felix annotations to register your commands class in the Roo
// container
@Service
public class WicketCommands implements CommandMarker { // All command types must
														// implement the
														// CommandMarker
														// interface

	/**
	 * Get a reference to the WicketOperations from the underlying OSGi
	 * container
	 */
	@Reference
	private WicketOperations operations;

	/**
	 * This method is optional. It allows automatic command hiding in situations
	 * when the command should not be visible. For example the 'entity' command
	 * will not be made available before the user has defined his persistence
	 * settings in the Roo shell or directly in the project.
	 * 
	 * You can define multiple methods annotated with
	 * {@link CliAvailabilityIndicator} if your commands have differing
	 * visibility requirements.
	 * 
	 * @return true (default) if the command should be visible at this stage,
	 *         false otherwise
	 */
	@CliAvailabilityIndicator({ "wicket setup" })
	public boolean isSetupCommandAvailable() {
		return operations.isSetupCommandAvailable();
	}

	/**
	 * This method registers a command with the Roo shell. It has no command
	 * attribute.
	 * 
	 */
	@CliCommand(value = "wicket setup", help = "Install Wicket dependencies, Wicket servlet filter and all common Wicket artifacts.")
	public void setup(
			@CliOption(key = "webPackage", mandatory = false, //
			help = "The package in which the Wicket application class will be placed."
					+ "Defaults to subpackage 'web' under top level package."
					+ "If Wicket has been setup before, and there is already an application class, it is not allowed to set a different package.")//
			JavaPackage webPackage,
			@CliOption(key = "domainPackage", mandatory = false, //
			help = "The package in which additional domain related classes will be placed."
					+ "Defaults to subpackage 'domain' under top level package.")//
			JavaPackage domainPackage,
			@CliOption(key = "forceUpdate", mandatory = false, unspecifiedDefaultValue = "false", specifiedDefaultValue = "true", help = "Whether to force an update of the Java Classes and HTML files, if they already exist.")//
			boolean forceUpdate) {
		operations.setup(webPackage, domainPackage, forceUpdate);
	}
}